package pri.lt;

import edu.uci.ics.crawler4j.crawler.CrawlConfig;
import edu.uci.ics.crawler4j.crawler.CrawlController;
import edu.uci.ics.crawler4j.fetcher.PageFetcher;
import edu.uci.ics.crawler4j.robotstxt.RobotstxtConfig;
import edu.uci.ics.crawler4j.robotstxt.RobotstxtServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import pri.lt.dao.FetchHistoryDao;
import pri.lt.service.PostsRedisService;
import pri.lt.service.RedisService;

import java.io.File;
import java.io.InputStream;
import java.util.Properties;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@EnableScheduling
public class App
{

    protected static final Logger logger = LoggerFactory.getLogger(App.class);

    public static PostsRedisService postsRedisService;
    public static FetchHistoryDao fetchHistoryDao;

    public static void main( String[] args ) throws Exception {
        System.out.println( "Hello World!" );

        //更改properties配置文件名称,避免依赖冲突
        Properties properties = new Properties();
        InputStream in = App.class.getClassLoader().getResourceAsStream("mycrawler.properties");
        properties.load(in);
        SpringApplication app = new SpringApplication(App.class);
        app.setDefaultProperties(properties);
        ConfigurableApplicationContext context = app.run(args);
        postsRedisService = context.getBean(PostsRedisService.class);
        fetchHistoryDao = context.getBean(FetchHistoryDao.class);



    }

}
